def split(lst):
    n=len(lst)
    for i in range(n-1):
        if lst[i]==lst[-1]: return None
        if lst[i]>lst[-1]: #前面必须能分成比根节点小&大两部分。一旦比它大，后面必须都比它大
            if min(lst[i:n-1])<lst[-1]: 
                print(lst)
                return None
            return i
    return n-1

def solve(postorder):
    if len(postorder)<=1: return True 
    k=split(postorder)
    if not k: return False
    if k==len(postorder)-1 :return solve(postorder[:-1])
    return solve(postorder[:k]) and solve(postorder[k:-1])
    
postorder=[4,6,5,9,8]
print(solve(postorder))